package org.chunchu.todo.model;

import java.io.Serializable;

import android.widget.EditText;
import android.widget.TextView;

public class Task implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 6843244893992945545L;

	private long id;
	private String name;
	private String detail;
	private long categoryId;

	public Task() {

	}

	public Task(String name, String detail, long categoryId) {
		this.name = name.trim();
		this.detail = detail.trim();
		this.categoryId = categoryId;
	}

	public Task(long id, String name, String detail, long categoryId) {
		this.id = id;
		this.name = name.trim();
		this.detail = detail.trim();
		this.categoryId = categoryId;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDetail() {
		return detail;
	}

	public void setDetail(String detail) {
		this.detail = detail;
	}

	public long getCategoryId() {
		return categoryId;
	}

	public void setCategoryId(long categoryId) {
		this.categoryId = categoryId;
	}

	public boolean isNew() {
		return getId() == 0;
	}

	public void applyTo(TextView txtEditName, TextView txtEditDetail) {
		txtEditName.setText(getName());
		txtEditDetail.setText(getDetail());
	}

	public static Task from(EditText edtName, EditText edtDetail) {
		Task task = new Task(edtName.getText().toString(), edtDetail.getText()
				.toString(), 0);
		return task;
	}
}
